package com.lvcoding.cloud.common.core.response;

import com.lvcoding.cloud.common.core.constant.CommonConstant;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Res<T> implements Serializable {

    private int code;

    private String message;

    private T data;

    public static <T> Res<T> success(T data) {
        return createRes(CommonConstant.SUCCESS, null, data);
    }

    public static <T> Res<T> success(String message, T data) {
        return createRes(CommonConstant.SUCCESS, message, data);
    }

    public static <T> Res<T> success(int code, String message, T data) {
        return createRes(code, message, data);
    }

    public static <T> Res<T> fail(String message) {
        return createRes(CommonConstant.FAIL, message, null);
    }

    public static <T> Res<T> fail(String message, T data) {
        return createRes(CommonConstant.FAIL, message, data);
    }

    public static <T> Res<T> fail(int code, String message, T data) {
        return createRes(code, message, data);
    }

    public static <T> Res<T> createRes(int code, String message, T data) {
        Res<T> res = new Res<T>();
        res.setCode(code);
        res.setMessage(message);
        res.setData(data);
        return res;
    }
}
